﻿Public Class ClockDigit
    Dim pause As Boolean = False
    Private _phut As Integer
    Private _giay As Integer
    Public Property Phut() As Integer
        Get
            Return _phut
        End Get
        Set(ByVal value As Integer)
            _phut = value
        End Set
    End Property
    Public Property Giay() As Integer
        Get
            Return _giay
        End Get
        Set(ByVal value As Integer)
            _giay = value
        End Set
    End Property
    Public Sub ClockDigit()
        Me.Phut = 0
        Me.Giay = 0
    End Sub
    Public Sub ClockDigit(ByVal phut As Integer, ByVal giay As Integer)
        Me.Phut = phut
        Me.Giay = giay
    End Sub
    Public Sub ClockDigit(ByVal c As ClockDigit)
        Me.Phut = c.Phut
        Me.Giay = c.Giay
    End Sub
    Public Sub StartClock()
        Me.ClockDigit()
        TimeClock.Enabled = True
        TimeClock.Start()

    End Sub
    Public Sub StopClock()
        Me.ClockDigit()
        Dim p As String = Me.Phut.ToString("00")
        Dim g As String = Me.Giay.ToString("00")
        lblClock.Text = p & "-" & g
        TimeClock.Stop()
        TimeClock.Enabled = False
    End Sub
    Public Sub PauseClock()
        TimeClock.Stop()
        pause = True
    End Sub
    Public Sub ResumeClock()
        If (pause = True) Then
            TimeClock.Start()
        End If
    End Sub

    Private Sub TimeClock_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimeClock.Tick
        Dim p As String = Me.Phut.ToString("00")
        Dim g As String = Me.Giay.ToString("00")
        lblClock.Text = p & "-" & g
        Me.Giay = Me.Giay + 1
        If (Me.Giay = 10 And Me.Phut = 0) Then
            Me.PauseClock()
            RaiseEvent StopClockDigit("Hết giờ")

        End If
        If (Me.Giay = 60) Then
            Me.Phut = Me.Phut + 1
            Me.Giay = 0
        End If
        If (Me.Phut = 99 And Me.Giay = 59) Then
            Me.StopClock()
        End If
    End Sub
    Public Delegate Sub StopEventHandler(ByVal cd As String)
    Event StopClockDigit As StopEventHandler
End Class
